function atr(id){
	var auto = document.getElementById('a_i'+id);
	var atributo = document.getElementById('atri' + id); 
	if(atributo.value != ""){
		auto.disabled = false;
	}
	else{
		auto.disabled = true;
		auto.checked = false;
	}
}




function aumentarCampo(num){
	var tabla = document.getElementById('crearTabla').childNodes[0];
	var tr = document.createElement('tr');
	num++;
	tr.setAttribute('id', 'fila'+ num);
	tabla.appendChild(tr);
	tr = document.getElementById('fila'+num);
	var contenido = tabla.childNodes[1].innerHTML;
   	tr.innerHTML = contenido;
   	var contador = 0;
   	var a;
   	var b = '';
   	while((a = tr.childNodes[contador]) != null ){
   		a = a.childNodes[0];
   		a.setAttribute('name', a.name.substring(0, (a.name.length - 1)) + num);
   		if(a.name == 'atr'+num){
   			a.setAttribute('onchange','atr('+num+')');
   			a.setAttribute('id','atri'+num);
   		}
   		else if(a.name == 'a_i' + num){
   			a.setAttribute('id','a_i'+num);
   			a.disabled = true;
   		}
   		b = b + a.innerHTML;
   		contador++;
   	}
   	if(contador > 0){
   		document.getElementById('numCamposTabla').value = num;
   		restartButton(num);
   	}
}

function quitarCampo(num){
	if(num>1){
		var tabla = document.getElementById('crearTabla');
		//tabla.childNodes[0].childNodes[num].innerHTML = '';
		var nodo = tabla.childNodes[0]; 
		tabla.childNodes[0].removeChild(nodo.childNodes[num]);
		restartButton(num - 1);
	}
}

function restartButton(numero){
	var btnQuitar = document.getElementById('quitar');
	var btnPoner = document.getElementById('aniadir');
	btnPoner.setAttribute('onclick','aumentarCampo('+numero+')');
	btnQuitar.setAttribute('onclick','quitarCampo('+numero+')');
	if(numero == 1){
		btnQuitar.disabled = true;
		btnQuitar.setAttribute("class", "botonDesactivado boton");
	}else{
		btnQuitar.disabled = false;
		btnQuitar.setAttribute("class", "boton");
	}
}